import store from '../index'
const state = {
  platformType: {
    YYZX: '_a_g_umc',                  // [常量]用户运营中心
    XSZB: '_a_g_xs',                   // [常量]销司总部
    FGLY: '_a_g_d_',                   // [常量]分公司管理员
    XSDB: '_a_u_',                   // [常量]销售代表
  },
  ctype: {
    BSXF: 0,                           // [常量]贬损下发
    BSZH: 1,                           // [常量]贬损转换
    ECHF: 2,                           // [常量]二次回访
    FGLY: 3,                           // [常量]分公司管理员
  },
  // userType: '_a_g_xs',                // _a_g_umc: 用户运营中心； _a_g_xs: 销司总部；_a_g_d_: 分公司管理员
  deroType: 0,                    // 0: 贬损下发；1: 贬损转换；2: 二次回访 3: 分公司管理员
  currentOrderUserType: '',
  currentOrderCtype: '',
  currentOrderStatus: '',
  currentOrderDetails: {}
}

const getters = {
  userType() {
    let type = ''
    switch (store.state.userInfo.characterId) {
      case 5:
        type = '_a_g_umc'
        break
      case 6:
        type = '_a_g_xs'
        break
      case 7:
        type = '_a_g_d_'
        break
    }
    return type
  },
  disparageType(state, getters) {
    return getters.userType === '_a_g_d_' ? 3 : state.deroType
  }
}

const mutations = {

  // 设置用户类型
  ['SET_USERTYPE'](state, userId) {
    let type = ''
    switch (userId) {
      case 5:
        type = '_a_g_umc'
        break
      case 6:
        type = '_a_g_xs'
        break
      case 7:
        type = '_a_g_d_'
        break
    }
    state.userType = type
  },

  // 设置贬损类型
  ['SET_DEROTYPE'](state, deroType) {
    state.deroType = deroType;
  },

  // 设置当前订单用户类型
  ['SET_CURRENTORDERUSERTYPE'](state, characterId) {
    const regs = [/^_a_g_umc/, /^_a_g_xs/, /^_a_g_d_/, /^_a_u_/]
    const index = regs.findIndex(item => item.test(characterId))
    const userType = index > -1 ? regs[index].toString().replace(/[/^]/g, '') : ''
    state.currentOrderUserType = userType;
  },

  // 设置当前订单ctype
  ['SET_CURRENTORDERCTYPE'](state, ctype) {
    state.currentOrderCtype = ctype;
  },

  // 设置当前订单状态
  ['SET_CURRENTORDERSTATUS'](state, status) {
    state.currentOrderStatus = status;
  },

  // 设置订单详情
  ['SET_CURRENTORDERDETAILS'](state, details) {
    state.currentOrderDetails = details;
  },

}

const actions = {

}

export default {
  state,
  getters,
  actions,
  mutations
}

